package live.common;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import live.common.PropertiesManager;

public class PropertiesManager {
	private static Properties prop = null;
	private String path = PropertiesManager.class.getResource("/").getPath()
			+ "config.properties";
	private FileInputStream is = null;
	static PropertiesManager instance = null;

	public static synchronized PropertiesManager getInstance() {
		if (instance == null) {
			instance = new PropertiesManager();
		}
		return instance;
	}

	public PropertiesManager() {
		try {
			prop = new Properties();
			String result = "";
			if (path.contains("%20") == true) {
				path = path.replaceAll("%20", " ");
			}
			is = new FileInputStream(path);
			prop.load(is);
			is.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String returnPostUrl(String key, String uri) {
		return returnValue(key, 0, uri);
	}

	public String returnPropValue(String key) {
		return returnValue(key, 1, null);
	}

	private String returnValue(String key, int type, String uri) {
		String result = "";
		switch (type) {
		case 0:
			result = prop.getProperty(uri) + prop.getProperty(key);
			break;
		case 1:
			result = prop.getProperty(key);
			break;
		}
		return result;
	}
}
